package com.SuanFa.test;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;

//地雷格
public class test9 {
   static Scanner sc=new Scanner(System.in);
   static int x = sc.nextInt();
   static int y = sc.nextInt();
    public static void main(String[] args) {
        String[][]strs=new String[x][y];
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                strs[i][j]=sc.next();
            }
        }
        String[][] check = check(strs);
        System.out.println(Arrays.deepToString(check));
    }
    public static String[][] check(String[][] strs){
        String[][]strings=new String[x][y];
        int temp=0;
        for (int i = 0; i < strs.length; i++) {
            for (int j = 0; j < strs[i].length; j++) {
                if (Objects.equals(strs[i][j], "*")){
                    strings[i][j]="*";
                }else {
                    if (j-1>=0){
                        if (strs[i][j-1].equals("*")){
                            temp++;
                        }
                        if(i-1>=0&&strs[i-1][j-1].equals("*")){
                            temp++;
                        }

                        if (i+1< x&&strs[i+1][j-1].equals("*")){
                            temp++;
                        }
                    }
                    if (i-1>=0&&strs[i-1][j].equals("*")){
                        temp++;
                    }
                    if (i+1<x&&strs[i+1][j].equals("*")){
                        temp++;
                    }
                    if (j+1<y){
                        if (strs[i][j+1].equals("*")){
                            temp++;
                        }
                        if(i-1>=0&&strs[i-1][j+1].equals("*")){
                            temp++;
                        }
                        if (i+1< x&&strs[i+1][j+1].equals("*")){
                            temp++;
                        }
                    }
                    strings[i][j]=temp+"";
                    temp=0;
                }
            }
        }
        return strings;
    }
}
//3 3
//*??
//???
//?*?

